<!DOCTYPE html>
<html class="x-admin-sm" xmlns:th="http://www.thymeleaf.org">
<head>
    <meta charset="UTF-8">
    <title>农资商城销售系统</title>
    <meta name="renderer" content="webkit">
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
    <meta name="viewport"
          content="width=device-width,user-scalable=yes, minimum-scale=0.4, initial-scale=0.8,target-densitydpi=low-dpi"/>
    <link rel="stylesheet" th:href="@{/admin/css/font.css}">
    <link rel="stylesheet" th:href="@{/admin/css/layui.css}">
    <link rel="stylesheet" th:href="@{/admin/css/xadmin.css}">
    <script type="text/javascript" th:src="@{/admin/js/jquery-3.5.1.min.js}"></script>
    <script type="text/javascript" th:src="@{/admin/lib/layui/layui.js}"></script>
    <script type="text/javascript" th:src="@{/admin/js/global.js}"></script>
    <script type="text/javascript" th:src="@{/admin/js/layui.js}"></script>
    <script type="text/javascript" th:src="@{/admin/js/xadmin.js}"></script>
</head>
<body>

<div class="layui-fluid">
    <div class="layui-row layui-col-space15">
        <div class="layui-col-md12">
            <div class="layui-card">
                <div class="layui-card-body ">
                    <form class="layui-form layui-col-space5">
                        <div class="layui-inline layui-show-xs-block" style="display: none;">
                            <input class="layui-input" autocomplete="off" placeholder="用户id" name="userid" id="userid">
                        </div>
                        <div class="layui-inline layui-show-xs-block">
                            <input class="layui-input" autocomplete="off" placeholder="姓名" name="shname" id="shname">
                        </div>
                        <div class="layui-inline layui-show-xs-block">
                            <input class="layui-input" autocomplete="off" placeholder="电话" name="shphone"
                                   id="shphone">
                        </div>
                        <div class="layui-inline layui-show-xs-block">
                            <input class="layui-input" autocomplete="off" placeholder="省份" name="shprovince"
                                   id="shprovince">
                        </div>
                        <div class="layui-inline layui-show-xs-block">
                            <input class="layui-input" autocomplete="off" placeholder="详细地址" name="shjaddress"
                                   id="shjaddress">
                        </div>
                        <div class="layui-inline layui-show-xs-block">
                            <button class="layui-btn" lay-submit="" lay-filter="sreach"><i
                                    class="layui-icon">&#xe615;</i></button>
                        </div>
                    </form>
                </div>
                <div class="layui-card-body layui-table-body layui-table-main">
                    <table id="test" class="layui-hide" lay-filter="test"></table>
                </div>
            </div>
        </div>
    </div>
</div>

</body>
<script>

    layui.use(['laydate', 'form', 'table'], function () {
        var laydate = layui.laydate;
        var form = layui.form;
        var table = layui.table;

        //初始化表格数据
        table.render({
            elem: '#test',
            url: prefix + '/useradress/selectAll',
            method: "get",
            where: {
                userid: $("#userid").val(),
                shname: $("#shname").val(),
                shphone: $("#shphone").val(),
                shprovince: $("#shprovince").val(),
                shjaddress: $("#shjaddress").val()
            },
            title: '收货地址列表',
            page: true,
            id: 'liebiao',
            parseData: function (res) {
                return {
                    "code": 0,
                    "msg": res.msg,
                    "count": res.data.count,
                    "data": res.data.data
                }
            },
            cols: [
                [
                    {
                        field: 'shname',
                        title: '收货人姓名',
                        align: 'center',
                    },
                    {
                        field: 'shphone',
                        title: '收货人电话',
                        align: 'center'
                    }, {
                    field: 'shprovince',
                    title: '省份',
                    align: 'center',
                }, {
                    field: 'shcity',
                    title: '市区',
                    align: 'center',
                },
                    {
                        field: 'district',
                        title: '区/县',
                        align: 'center'
                    }, {
                    field: 'shstreet',
                    title: '街道',
                    align: 'center',
                }, {
                    field: 'shjaddress',
                    title: '详细地址',
                    align: 'center'
                }, {
                    field: 'dedaultadress',
                    title: '是否默认地址',
                    align: 'center',
                    templet: function (d) {
                        if (d.dedaultadress === 1) {
                            return "是"
                        } else {
                            return "否"
                        }
                    }
                }
                ]
            ]
        });

        // 搜索提交
        form.on('submit(sreach)', function (data) {
            let field = data.field; // 获得表单字段
            // 执行搜索重载
            table.reload('liebiao', {
                page: {
                    curr: 1 // 重新从第 1 页开始
                },
                where: field // 搜索的字段
            });
            return false; // 阻止默认 form 跳转
        });


    });


</script>
</html>